package com.force.module.webserver.htmlast;

import lombok.Data;

import java.util.Arrays;

@Data
public class Template {

	private String htmlName="template";
	private String asComponent="component";

	private HtmlDom start;

	private HtmlDom end;

	private String templateName="    <script>\n" +
			"        export default {\n" +
			"            tag: 'tName'\n" +
			"        }\n" +
			"    </script>";


	public String buildTemplate(String content,String templateName){
		String startStr = start.include(htmlName, asComponent);
		String endStr = end.include(htmlName, true);
		String templateNameStr = this.templateName.replace("tName", templateName);
		String include = include(startStr, endStr,content, templateNameStr);

		return include;
	}

	private  String include(String left,String right,String content,String templateName){
		StringBuffer stringBuffer=new StringBuffer();
		stringBuffer.append(left);
		stringBuffer.append(content);
		stringBuffer.append(templateName);
		stringBuffer.append(right);
		return stringBuffer.toString();
	}

	public static void main(String[] args) {
		Template template=new Template();
		String s = template.buildTemplate("你好", "demo-text");
		System.out.println(s);
	}
}
